//
//  WWAttentionDoctorTableViewCell.m
//  快医
//
//  Created by 张湾湾 on 16/7/6.
//
//

#import "WWAttentionDoctorTableViewCell.h"
#import "UIImage+ProfileImage.h"
#import <UIImageView+WebCache.h>

#import "WWMarginButton.h"
@interface WWAttentionDoctorTableViewCell()

/**头像*/
@property (nonatomic,weak)UIImageView *iconImageView;
/**姓名*/
@property (nonatomic,weak)UILabel *nameLabel;
/**级别*/
@property (nonatomic,weak)UILabel *honorLabel;
/**所属医院*/
@property (nonatomic,weak)UILabel *hospitalLabel;

// 放置3个button 的view
@property (nonatomic,weak)UIView *tempView;

/**添加按钮*/
@property (nonatomic,weak)WWMarginButton *addButton;
/**鲜花*/
@property (nonatomic,weak)WWMarginButton *flowerButton;
/**收藏*/
@property (nonatomic,weak)WWMarginButton *collectionButton;
/**匹配*/
@property (nonatomic,weak)UIButton *mateButton;

@end

@implementation WWAttentionDoctorTableViewCell
- (void)setModel:(WWPayAttentionModel *)model{
    
    _model = model;
    
    //MARK: - 赋值
        
    [self.iconImageView setProfileImageWithImageURLPath:model.doctor_portrait];

//    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait]];
    self.nameLabel.text = model.doctor_name;
    self.honorLabel.text = model.doctor_title_name;
    self.hospitalLabel.text = model.doctor_hospital_name;
    [self.flowerButton setTitle:model.flower forState:UIControlStateNormal];
    [self.addButton setTitle:model.operation_count forState:UIControlStateNormal];
    [self.collectionButton setTitle:model.banner forState:UIControlStateNormal];
    [self.mateButton setTitle:[NSString stringWithFormat:@"匹配度\n%@",model.accuracy] forState:UIControlStateNormal];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        //MARK: - 创建控件
        [self setupUI ];
        //MARK: - 布局位置
        [self setupConstrains];
    }
    return self;
    
}
#pragma mark
#pragma mark - 创建
- (void)setupUI{
    
    //MARK: - 头像
    UIImageView * iconImageView = [[UIImageView alloc]init];
    self.iconImageView = iconImageView;
    [[UIImage imageNamed:@"illness_img_person.png"] profileImageWithProfileImageBlock:^(UIImage *image) {
        
        self.iconImageView.image = image;
    }];
    
    [self.contentView addSubview:iconImageView];
    
    //MARK: - 姓名
    UILabel * nameLabel = [[UILabel alloc]init];
    self.nameLabel = nameLabel;
    self.nameLabel.textColor = [UIColor blackColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    
    [self.contentView addSubview:nameLabel];
    
    //MARK: - 级别
    UILabel * honorLabel = [[UILabel alloc]init];
    self.honorLabel = honorLabel;
    self.honorLabel.textColor = [UIColor grayColor];
    self.honorLabel.font = [UIFont systemFontOfSize:13];

    
    [self addSubview:honorLabel];
    
    //MARK: - 医院
    UILabel * hosptilLabel = [[UILabel alloc]init];
    self.hospitalLabel = hosptilLabel;
    self.hospitalLabel.textColor = [UIColor grayColor];
    self.hospitalLabel.font = [UIFont systemFontOfSize:13];

    
    [self addSubview:hosptilLabel];
    
    //MARK: - 临时防止三个button的view
    UIView * tempView = [[UIView alloc]init];
    self.tempView = tempView;
//    self.tempView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:tempView]
    ;
    //MARK: - 加
    WWMarginButton * addButton = [[WWMarginButton alloc]init];
    self.addButton = addButton;
    [self.addButton setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];

    [self.addButton setTitleColor:XHRColorWithRGB(119, 210, 210) forState:UIControlStateNormal];
    self.addButton.titleLabel.font  = [UIFont systemFontOfSize:12];
    
    [self.tempView addSubview:addButton];
    
    //MARK: - 鲜花
    WWMarginButton * flowerButton = [[WWMarginButton alloc]init];
    self.flowerButton = flowerButton;
    [self.flowerButton setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];

    [self.flowerButton setTitleColor:XHRColorWithRGB(119, 210, 210) forState:UIControlStateNormal];
    self.flowerButton.titleLabel.font = [UIFont systemFontOfSize:12];
    
    [self.tempView addSubview:flowerButton];
    
    //MARK: - 收藏
    WWMarginButton * collectionButton = [[WWMarginButton alloc]init];
    self.collectionButton = collectionButton;
    [self.collectionButton setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
    [self.collectionButton setTitleColor:XHRColorWithRGB(119, 210, 210) forState:UIControlStateNormal];
    self.collectionButton.titleLabel.font  = [UIFont systemFontOfSize:12];
    
    [self.tempView addSubview:collectionButton];
    
    //MARK: - 匹配
    UIButton * mateButton = [[UIButton alloc]init];
    self.mateButton = mateButton;
    [mateButton setTitle:@"匹配度" forState:UIControlStateNormal];
    [mateButton setBackgroundImage:[UIImage imageNamed:@"pipeidu"] forState:UIControlStateNormal];
    
    self.mateButton.titleLabel.font = [UIFont systemFontOfSize:13];
    
    self.mateButton.titleLabel.numberOfLines = 0;
    self.mateButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    
    [self addSubview:mateButton];
    
}

#pragma mark
#pragma mark - 布局位置,设置约束
- (void)setupConstrains{
    //MARK: - 头像约束
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(20);
        make.centerY.equalTo(self);
        make.width.height.equalTo(90);
    }];
    
    //MARK: - 姓名
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.top).offset(5);
        make.leading.equalTo(self.iconImageView.trailing).offset(5);
    }];
    
    //MARK: - 级别
    [self.honorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.top);
        make.leading.equalTo(self.nameLabel.trailing).offset(15);
    }];
    
    //MARK: - 医院
    [self.hospitalLabel makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.nameLabel.leading);
        make.top.equalTo(self.nameLabel.bottom).offset(10);
        make.width.equalTo(100);
        
        
    }];
    
    //MARK: - 临时的view
    [self.tempView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hospitalLabel.bottom).offset(5);
        make.leading.equalTo(self.hospitalLabel.leading);
        make.height.equalTo(30);
        make.width.equalTo(160);
        
    }];
    
    //MARK: - 添加
    [self.addButton makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(0);
        make.centerY.equalTo(self.tempView);
        make.width.equalTo(50);
        
    }];
    
    //MARK: - 鲜花
    [self.flowerButton makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.tempView);
        make.leading.equalTo(self.addButton.trailing).offset(5);
        make.width.equalTo(50);
    }];
    
    //MARK: - 收藏
    [self.collectionButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tempView);
        make.leading.equalTo(self.flowerButton.trailing).offset(5);
        make.width.equalTo(50);
    }];
    
    //MARK: - 末尾
    [self.mateButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(-2);
        make.trailing.equalTo(-30);
        make.height.equalTo(70);
        
    }];
    
}

- (void)setFrame:(CGRect)frame{
    frame.size.height -= 20;
    frame.origin.y += 20;
    
    [super setFrame:frame];
}


@end
